<template>
    <div style="padding: 10px;">
        <el-card>
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item :label="$t('用户id')">
                    <el-input size="small" v-model="formInline.userId"></el-input>
                </el-form-item>
                <el-form-item :label="$t('用户名称')">
                    <el-input size="small" v-model="formInline.userName"></el-input>
                </el-form-item>
                <el-form-item :label="$t('流水号')">
                    <el-input size="small" v-model="formInline.flowId"></el-input>
                </el-form-item>
                <el-form-item :label="$t('渠道名称')">
                    <el-select size="small" v-model="formInline.channel">
                        <el-option label="充值" :value="0"></el-option>
                        <el-option label="cfp转usdt" :value="1"></el-option>
                        <el-option label="usdt转cfp" :value="2"></el-option>
                        <el-option label="提现" :value="3"></el-option>
                        <el-option label="提现失败" :value="4"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item :label="$t('创建时间')">
                    <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="formInline.createTime" size="small"
                        type="datetime" :placeholder="$t('选择日期时间')">
                    </el-date-picker>
                </el-form-item> -->
                <el-form-item>
                    <el-button size="small" type="primary" @click="onSubmit">{{ $t('query') }}</el-button>
                    <el-button size="small" type="warning" @click="reset">{{ $t('重置') }}</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card style="margin-top: 10px;">
            <div style="margin-bottom: 20px;">
                <el-date-picker size="small" value-format="yyyy-MM-dd HH:mm:ss" v-model="timeList" type="datetimerange"
                    align="right" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
                <el-button size="small" style="margin-left: 20px;" @click="sync" type="primary">定时任务执行</el-button>
            </div>
            <el-table v-loading="loading" :data="tableData" style="width: 100%">
                <el-table-column prop="userId" :label="$t('用户id')"> </el-table-column>
                <el-table-column prop="userName" :label="$t('用户昵称')">
                </el-table-column>
                <el-table-column prop="flowId" :label="$t('流水号')">
                </el-table-column>
                <el-table-column :label="$t('渠道名称')">
                    <template #default="{ row }">
                        {{ $t(`${type[row.channel].label}`) }}
                    </template>
                </el-table-column>
                <el-table-column prop="usdtAmount" :label="$t('usdt数量')">
                </el-table-column>
                <el-table-column prop="usdtBalance" :label="$t('usdt结余')">
                </el-table-column>
                <el-table-column prop="cfpAmount" :label="$t('cfp数量')">
                </el-table-column>
                <el-table-column prop="cfpBalance" :label="$t('cfp结余')">
                </el-table-column>
                <el-table-column prop="createTime" :label="$t('下单时间')">
                </el-table-column>
                <el-table-column prop="executionTime" :label="$t('定时任务执行时间')">
                </el-table-column>
                <!-- <el-table-column prop="incomeAmount" :label="$t('收入金额')">
          </el-table-column>
          <el-table-column prop="transferExpenses" :label="$t('转账支出')">
          </el-table-column>
          <el-table-column prop="flowPackageExpenditure" :label="$t('购买流量包支出')">
          </el-table-column>
          <el-table-column prop="statusName" :label="$t('状态')">
            <template #default="{ row }">
              {{ $t(`${row.statusName}`) }}
            </template>
          </el-table-column>
          <el-table-column prop="channelName" :label="$t('渠道名称')">
            <template #default="{ row }">
              {{ $t(`${row.channelName}`) }}
            </template>
          </el-table-column> -->
                <el-table-column prop="createTime" :label="$t('创建时间')">
                </el-table-column>
            </el-table>
            <el-pagination style="float: right;margin: 5px 0;" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>
<script>
import { getUsdtIncomeListApi, getUsdtSyncApi } from "@/api/appuser/usdtIncomeList.js";
const currentDate = new Date();
const previousDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000); // 前一天的日期

// 设置时、分、秒为零
previousDate.setHours(0, 0, 0, 0);
// currentDate.setHours(0, 0, 0, 0);

function formatDate(date) {
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hours = date.getHours().toString().padStart(2, '0');
    const minutes = date.getMinutes().toString().padStart(2, '0');
    const seconds = date.getSeconds().toString().padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
export default {
    data() {
        return {
            tableData: [],
            loading: false,
            total: 0,
            page: {
                pageNum: 1,
                pageSize: 10,
            },
            formInline: {
                userId: null,
                userName: null,
                channel: null,
                flowId: null
            },
            type: {
                0: {
                    value: "+",
                    label: "充值",
                },
                1: {
                    value: "+",
                    label: "cfp转usdt",
                },
                2: {
                    value: "+",
                    label: "usdt转cfp",
                },
                3: {
                    value: "+",
                    label: "提现",
                },
                4: {
                    value: "+",
                    label: "提现失败",
                },
            },
            timeList: [formatDate(previousDate), formatDate(currentDate)],
        };
    },
    created() {
        this.getUsdtIncomeList();
    },
    methods: {
        async getUsdtIncomeList() {
            this.loading = true;
            const res = await getUsdtIncomeListApi({
                ...this.page,
                ...this.formInline,
                // userName: "333@qq.com",
            });
            console.log(res);
            this.tableData = res.list;
            this.total = res.total;
            this.loading = false;
        },
        handleSizeChange(val) {
            this.page.pageSize = val;
            this.getUsdtIncomeList();
        },
        handleCurrentChange(val) {
            this.page.pageNum = val;
            this.getUsdtIncomeList();
        },
        onSubmit() {
            console.log(this.formInline);
            this.page = {
                pageNum: 1,
                pageSize: 10,
            };
            this.getUsdtIncomeList();
        },
        reset() {
            this.page = {
                pageNum: 1,
                pageSize: 10,
            };
            this.formInline = {
                userId: null,
                userName: null,
                statusName: null,
                createTime: null,
            };
            this.getUsdtIncomeList();
        },
        async sync() {
            console.log(this.timeList);
            this.$confirm('确认执行吗', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                await await getUsdtSyncApi({
                    startTime: this.timeList[0],
                    endTime: this.timeList[1]
                })
                this.$message({
                    type: 'success',
                    message: '执行成功!'
                });
            }).catch(() => {
                // this.$message({
                //     type: 'info',
                //     message: '已取消'
                // });
            });

        },
    },
};
</script>
<style lang='' scoped>
  </style>